package us.icitap.cm.business.entities;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.eclipse.persistence.annotations.Customizer;

import us.icitap.cm.utils.MyCustomizer;

@Entity
@Customizer(MyCustomizer.class)
@Table(name="ORGANIZATION", schema="MPC")
public class Organization implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = -864185545718568678L;


	@Id
	@Column(insertable=false, updatable = false)
	private Integer id;
	

	@OneToOne
	@JoinColumn(name="ID",nullable=false)
	private AppEntity appEntity;
	
	@ManyToOne
	@JoinColumn(name="ORG_CLASSIFICATION_ID")
	private AppList orgClassification;
	
	@ManyToOne
	@JoinColumn(name="ORG_TYPE_ID")
	private AppList organizationType;
	
	@Column(length=150)
	private String name;
	
	@Column(length=500)
	private String notes;
	
	@Column(name="MEMBER_NO")
	private Integer memberNo;
	
	

	public Organization() {
		// TODO Auto-generated constructor stub
	}
	
	public Organization(Organization organization) {
		this.name = organization.getName();
		this.notes = organization.getNotes();
		this.organizationType = organization.getOrganizationType();
		
				
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public AppEntity getAppEntity() {
		return appEntity;
	}

	public void setAppEntity(AppEntity appEntity) {
		this.appEntity = appEntity;
	}

	public AppList getOrganizationType() {
		return organizationType;
	}

	public void setOrganizationType(AppList organizationType) {
		this.organizationType = organizationType;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getNotes() {
		return notes;
	}

	public void setNotes(String notes) {
		this.notes = notes;
	}

	

	@Override
	public String toString() {
		if(this.organizationType != null)
			if(this.name != null) return this.organizationType.getTag() + ", " + this.name;
			else return this.organizationType.getTag();
		else return "Organizatata nr. " + (id + 1);
	}

	public AppList getOrgClassification() {
		return orgClassification;
	}

	public void setOrgClassification(AppList orgClassification) {
		this.orgClassification = orgClassification;
	}

	public Integer getMemberNo() {
		return memberNo;
	}

	public void setMemberNo(Integer memberNo) {
		this.memberNo = memberNo;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result
				+ ((memberNo == null) ? 0 : memberNo.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + ((notes == null) ? 0 : notes.hashCode());
		result = prime
				* result
				+ ((orgClassification == null) ? 0 : orgClassification
						.hashCode());
		result = prime
				* result
				+ ((organizationType == null) ? 0 : organizationType.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Organization other = (Organization) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (memberNo == null) {
			if (other.memberNo != null)
				return false;
		} else if (!memberNo.equals(other.memberNo))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (notes == null) {
			if (other.notes != null)
				return false;
		} else if (!notes.equals(other.notes))
			return false;
		if (orgClassification == null) {
			if (other.orgClassification != null)
				return false;
		} else if (!orgClassification.equals(other.orgClassification))
			return false;
		if (organizationType == null) {
			if (other.organizationType != null)
				return false;
		} else if (!organizationType.equals(other.organizationType))
			return false;
		return true;
	}
	
	public boolean myEquals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Organization other = (Organization) obj;
		
		if (memberNo == null) {
			if (other.memberNo != null)
				return false;
		} else if (!memberNo.equals(other.memberNo))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (notes == null) {
			if (other.notes != null)
				return false;
		} else if (!notes.equals(other.notes))
			return false;
		if (orgClassification == null) {
			if (other.orgClassification != null)
				return false;
		} else if (!orgClassification.equals(other.orgClassification))
			return false;
		if (organizationType == null) {
			if (other.organizationType != null)
				return false;
		} else if (!organizationType.equals(other.organizationType))
			return false;
		return true;
	}
}
